<link rel="stylesheet" href="__STATIC__/module/admin/ext/datetimepicker/css/datetimepicker.css" type="text/css">
<link rel="stylesheet" href="__STATIC__/module/admin/ext/datetimepicker/css/dropdown.css" type="text/css">

<div class="box">
    <div class="box-header">
        <h3 class="box-title">{if condition="isset($info)"}编辑公告{else/}添加公告{/if}</h3>
    </div>
    
    <div class="box-body">
        <form action="" method="post" class="form-horizontal">
            {if condition="isset($info)"}
            <input type="hidden" name="id" value="{$info.id}">
            {/if}
            
            <div class="form-group">
                <label class="col-sm-2 control-label">公告标题</label>
                <div class="col-sm-10">
                    <input type="text" name="title" value="{$info.title ?? ''}" placeholder="请输入公告标题" class="form-control" required>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">公告类型</label>
                <div class="col-sm-10">
                    <select name="type" class="form-control" required>
                        <option value="">请选择公告类型</option>
                        {volist name="type_options" id="option"}
                        <option value="{$key}" {if condition="isset($info) && $info.type == $key"}selected{/if}>{$option}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">公告图片</label>
                <div class="col-sm-10">
                    {assign name="image_url" value="$info.image_url|default=''" /}
                    {:widget('file/index', ['name' => 'image_url', 'value' => $image_url, 'type' => 'img'])}
                    <div class="help-block">
                        <small class="text-muted">请上传单张公告图片，支持jpg、png、gif格式（可选）</small>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">公告内容</label>
                <div class="col-sm-10">
                    <textarea name="content" placeholder="请输入公告内容" class="form-control textarea_editor" rows="8" required>{$info.content ?? ''}</textarea>
                    {:widget('editor/index', array('name'=> 'content','value'=> $info.content ?? ''))}
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-10">
                    <input type="number" name="sort" value="{$info.sort ?? 0}" placeholder="数字越大越靠前" class="form-control">
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">状态</label>
                <div class="col-sm-10">
                    <select name="announcement_status" class="form-control">
                        {volist name="status_options" id="option"}
                        <option value="{$key}" {if condition="isset($info) && $info.announcement_status == $key"}selected{elseif condition="!isset($info) && $key == 1"/}selected{/if}>{$option}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            
            <div class="form-group">
                <label class="col-sm-2 control-label">发布时间</label>
                <div class="col-sm-10">
                    <input type="text" name="publish_time" value="{$info.publish_time ?? ''}" placeholder="留空则使用当前时间" class="form-control" id="publish_time">
                    <div class="help-block">
                        <small class="text-muted">格式：YYYY-MM-DD HH:mm:ss，留空则使用当前时间</small>
                    </div>
                </div>
            </div>
            
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-primary">立即提交</button>
                    <ob_link><a href="{:url('announcementList')}" class="btn btn-default">返回列表</a></ob_link>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="__STATIC__/module/admin/ext/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="__STATIC__/module/admin/ext/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<script>
// 日期时间选择器初始化
$(function() {
    // 确保jQuery和datetimepicker插件已加载
    if (typeof $.fn.datetimepicker !== 'undefined') {
        $('#publish_time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
            autoclose: true,
            todayBtn: true,
            language: 'zh-CN',
            startView: 2,
            minView: 0,
            maxView: 4,
            forceParse: false,
            showMeridian: false,
            pickerPosition: 'bottom-left',
            weekStart: 1,
            todayHighlight: true,
            keyboardNavigation: true,
            clearBtn: true
        }).on('changeDate', function(e) {
            // 日期改变时的回调
            console.log('日期已选择:', e.date);
        });
    } else {
        console.error('datetimepicker插件未正确加载');
        // 降级处理：使用HTML5的datetime-local输入类型
        $('#publish_time').attr('type', 'datetime-local');
    }
});
</script>
